#!/bin/sh
#
# avahi-daemon init script

is-storage-box || is-tv-box || exit 0

if is-google-cast-enabled; then
  AVAHI_DAEMON_CONF="/etc/avahi/avahi-daemon-cast.conf"
else
  AVAHI_DAEMON_CONF="/etc/avahi/avahi-daemon.conf"
fi

case "$1" in
  start)
    nice babysit 60 avahi-daemon --file="$AVAHI_DAEMON_CONF" 2>&1 | logos avahi &
    ;;
  stop)
    avahi-daemon -c && avahi-daemon -k
    ;;
  reload)
    avahi-daemon -c && avahi-daemon -r
    ;;
  restart)
    stop avahi-daemon
    start avahi-daemon
    ;;
  *)
    echo "Usage: S50avahi-daemon {start|stop|reload|restart}" >&2
    exit 1
    ;;
esac
